﻿using BCCommon;
using BCCommon.Enums;
using BCData.MakeStaticPagingComponent.PageTemplate;
using BCData.MakeStaticPagingComponent.PageTemplateAttachment;
using BCData.MakeStaticPagingComponent.SystemServiceListing;
using BCData.MakeStaticPagingComponent.TemplateTag;
using BCDto.Common.WebsiteConfiguration;
using BCEntity.MakeStaticPagingComponent.PageTemplate;
using BCEntity.MakeStaticPagingComponent.SystemServiceListing;
using BCEntity.MakeStaticPagingComponent.TemplateTag;
using BCService.Common.WebsiteConfigurationService;
using BCService.MakeStaticPagingComponent.TagParseService;
using BCService.MakeStaticPagingComponent.WebsiteTemplateAttachmentService;
using Microsoft.Extensions.Configuration;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Text.RegularExpressions;

namespace BCService.MakeStaticPagingComponent.PageTemplateSerialize
{
    public class PageTemplateSerializeService : IPageTemplateSerializeService
    {
        private readonly IConfiguration configuration;
        private readonly IServiceProvider serviceProvider;
        private readonly IWebsiteConfigurationService websiteConfigurationService;
        private readonly IWebsiteTemplateAttachmentService websiteTemplateAttachmentService;
        private readonly IPageTemplateData pageTemplateData;
        private readonly IPageTemplateAttachmentData pageTemplateAttachmentData;
        private readonly ISystemServiceListingData systemServiceListingData;
        private readonly ITemplateTagData templateTagData;
        private readonly ITagParseService tagParseService;
        private const int SYSTEM_CONFIGURATION_ID = 1;
        private long? ContentId = null;
        private int? PageIndex { get; set; }
        private int? PageSize { get; set; }
        private bool IsPagingListPage { get; set; }
        private bool IsContentPage { get; set; }
        private PageTemplateEntity PageTemplateEntity { get; set; }
        public PageTemplateSerializeService(IConfiguration configuration,
            IServiceProvider serviceProvider,
            IWebsiteConfigurationService websiteConfigurationService,
            IWebsiteTemplateAttachmentService websiteTemplateAttachmentService,
            IPageTemplateData pageTemplateData,
            IPageTemplateAttachmentData pageTemplateAttachmentData,
            ISystemServiceListingData systemServiceListingData,
            ITemplateTagData templateTagData,
            ITagParseService tagParseService)
        {
            this.configuration = configuration;
            this.serviceProvider = serviceProvider;
            this.websiteConfigurationService = websiteConfigurationService;
            this.websiteTemplateAttachmentService = websiteTemplateAttachmentService;
            this.pageTemplateData = pageTemplateData;
            this.pageTemplateAttachmentData = pageTemplateAttachmentData;
            this.systemServiceListingData = systemServiceListingData;
            this.templateTagData = templateTagData;
            this.tagParseService = tagParseService;
        }

        public WebsiteConfigurationDto WebsiteConfigurationDto { get; set; }

        #region 构建分页页面操作
        public string MakePagingOperation(PageTemplateEntity pageTemplateEntity, int pageIndex, int pageSize)
        {
            if (pageTemplateEntity == null)
            {
                throw new ArgumentException("当前网站模板不存在此页面。");
            }

            this.WebsiteConfigurationDto = websiteConfigurationService.Get(SYSTEM_CONFIGURATION_ID);

            string html = pageTemplateEntity.PageHtml;
            this.PageTemplateEntity = pageTemplateEntity;
            this.IsPagingListPage = pageTemplateEntity.IsPagingListPage;
            this.IsContentPage = pageTemplateEntity.IsContentPage;
            this.PageIndex = pageIndex;
            this.PageSize = pageSize;

            //解析系统定义模板标记
            do
            {
                html = ParseSystemDefinedTag(html);
            }
            while (MatchSystemDefinedTag(html).Count > 0);


            //解析动态模板标记
            do
            {
                html = ParseDynamicTagcode(html);
            }
            while (MatchDynamicTag(html).Count > 0);

            //解析For循环标记
            /* 
             * 示例：
             * {{BCFor abc(1,work)}}
             *   <div>{{$$name}}</div>
             * {{/BCFor}}
             */
            List<string> forTemplate = GetForTemplate(html);
            foreach (string item in forTemplate)
            {
                html = ReplaceSystemTagTemplateInlineDynamicTag(html, item, "BCFor");
            }
            if (pageTemplateEntity.IsPagingListPage) {
                //解析Pageable分页标记
                List<string> pageableTemplate = GetPageableTemplate(html);
                foreach (string item in pageableTemplate)
                {
                    List<object> param = pageTemplateEntity.PagingListServiceParams.Split(',').ToList<object>();
                    param.Add(pageIndex);
                    param.Add(pageSize);
                    html = GetPagingServiceMethodResult(html, item, pageTemplateEntity.PagingListServiceTag,param);
                }
            }
            //解析Object按钮标记
            List<string> previouTemplate = GetObjectTemplate(html);
            foreach (string item in previouTemplate)
            {
                html = ReplaceSystemTagTemplateInlineObjectTag(html, item, "BCObject");
            }
            //获取系统配置标记并替换（即WebsiteConfiguration表中定义的）
            List<string> systemTag = this.MatchSystemConfigurationTag(html);
            html = this.ReplaceSystemTag(html, systemTag);
            string currentPath = this.GetParentPagePath(pageTemplateEntity);

            html = this.SettingHeadAndAppendAttachments(pageTemplateEntity, html);

            //保存Html到文件
            this.SaveHtml(html, currentPath, pageTemplateEntity.PageLevel, pageTemplateEntity.PageUrlName, pageIndex);
            return html;
        }

        #endregion

        #region 构建内容页面操作
        public string MakeContentPageOperation(PageTemplateEntity pageTemplateEntity,Object obj)
        {
            if (pageTemplateEntity == null)
            {
                throw new ArgumentException("当前网站模板不存在此页面。");
            }

            this.WebsiteConfigurationDto = websiteConfigurationService.Get(SYSTEM_CONFIGURATION_ID);

            object contentId = this.GetResultAnyFieldValue(obj, pageTemplateEntity.ContentPageCode);
            string html = pageTemplateEntity.PageHtml;
            this.PageTemplateEntity = pageTemplateEntity;
            this.IsPagingListPage = pageTemplateEntity.IsPagingListPage;
            this.IsContentPage = pageTemplateEntity.IsContentPage;
            this.ContentId = Convert.ToInt64(contentId);
            //解析动态模板标记
            do
            {
                html = ParseDynamicTagcode(html);
            }
            while (MatchDynamicTag(html).Count > 0);
            
            //解析For循环标记
            /* 
             * 示例：
             * {{BCFor abc(1,work)}}
             *   <div>{{$$name}}</div>
             * {{/BCFor}}
             */
            List<string> forTemplate = GetForTemplate(html);
            foreach (string item in forTemplate)
            {
                html = ReplaceSystemTagTemplateInlineDynamicTag(html, item, "BCFor");
            }
            
            //解析Object对象标记
            List<string> previouTemplate = GetObjectTemplate(html);
            foreach (string item in previouTemplate)
            {
                html = ReplaceSystemTagTemplateInlineObjectTag(html, item, "BCObject");
            }
            
            //获取系统配置标记并替换（即WebsiteConfiguration表中定义的）
            List<string> systemTag = this.MatchSystemConfigurationTag(html);
            html = this.ReplaceSystemTag(html, systemTag);

            //解析Content内容标记
            List<string> contentTemplate = GetContentTemplate(html);
            foreach (string item in contentTemplate)
            {
                string tagHtml = this.ParseContentTemplateResult(obj, item);
                html = html.Replace(item, tagHtml);
            }

            html = this.SettingHeadAndAppendAttachments(pageTemplateEntity, html);

            string currentPath = this.GetParentPagePath(pageTemplateEntity);

            //保存Html到文件
            this.SaveHtml(html, currentPath, pageTemplateEntity.PageLevel, pageTemplateEntity.PageUrlName, PageIndex);
            return html;
        }
        #endregion

        #region 构建页面操作
        public string MakePageOperation(PageTemplateEntity pageTemplateEntity)
        {
            if (pageTemplateEntity == null)
            {
                throw new ArgumentException("当前网站模板不存在此页面。");
            }

            this.WebsiteConfigurationDto = websiteConfigurationService.Get(SYSTEM_CONFIGURATION_ID);

            string html = pageTemplateEntity.PageHtml;

            //解析动态模板标记
            do
            {
                html = ParseDynamicTagcode(html);
            }
            while (MatchDynamicTag(html).Count > 0);

            //解析For循环标记
            /* 
             * 示例：
             * {{BCFor abc(1,work)}}
             *   <div>{{$$name}}</div>
             * {{/BCFor}}
             */
            List<string> forTemplate = GetForTemplate(html);
            foreach (string item in forTemplate)
            {
                html = ReplaceSystemTagTemplateInlineDynamicTag(html, item, "BCFor");
            }

            //解析Object对象标记
            List<string> previouTemplate = GetObjectTemplate(html);
            foreach (string item in previouTemplate)
            {
                html = ReplaceSystemTagTemplateInlineObjectTag(html, item, "BCObject");
            }

            //获取系统配置标记并替换（即WebsiteConfiguration表中定义的）
            List<string> systemTag = this.MatchSystemConfigurationTag(html);
            html = this.ReplaceSystemTag(html, systemTag);

            html = this.SettingHeadAndAppendAttachments(pageTemplateEntity, html);

            string currentPath = this.GetParentPagePath(pageTemplateEntity);

            //保存Html到文件
            this.SaveHtml(html, currentPath, pageTemplateEntity.PageLevel, pageTemplateEntity.PageUrlName, PageIndex);
            return html;
        }

        #endregion




        #region 获取分页服务方法结果
        /// <summary>
        /// 获取分页服务方法结果
        /// </summary>
        /// <param name="html">页面html</param>
        /// <param name="template">提取的标签模板</param>
        /// <param name="serviceName">服务名称</param>
        /// <param name="paras">服务参数</param>
        /// <returns></returns>
        private string GetPagingServiceMethodResult(string html, string template, string serviceName,List<object> paras)
        {
            SystemServiceListingEntity systemServiceListingEntity = this.systemServiceListingData.Get(SYSTEM_CONFIGURATION_ID, serviceName);
            if (systemServiceListingEntity == null)
            {
                throw new ArgumentException(string.Format("{0} 服务不存在", serviceName));
            }
            string templateHtmlResult = this.ReplaceSampleTag(systemServiceListingEntity, paras, template);

            return html.Replace(template, templateHtmlResult);
        }
        #endregion

        #region 获取服务方法结果
        /// <summary>
        /// 获取服务方法结果
        /// </summary>
        /// <param name="serviceMethodTag">服务方法标签</param>
        /// <param name="serviceMethodParams">服务方法参数</param>
        /// <returns></returns>
        public object GetServiceMethodResult(string serviceMethodTag, string serviceMethodParams)
        {
            List<object> paras = new List<object>();
            string serviceName = serviceMethodTag;
            Regex regex = new Regex("[(]{1}[\\s]*[a-zA-Z0-9_,?\"\\s]*[)]{1}");
            Match match = regex.Match(serviceMethodTag);
            if (match.Success)
            {
                serviceName = serviceName.Substring(0, serviceName.IndexOf('('));
                string value = match.Value.Replace("(", "").Replace(")", "");
                while (value.IndexOf(" ") > -1)
                {
                    value = value.Replace(" ", "");
                }
                paras = value.Split(',').ToList<object>();
            }
            if (paras.Count == 0 && !string.IsNullOrWhiteSpace(serviceMethodParams) && serviceMethodParams.IndexOf(",") != -1)
            {
                paras = serviceMethodParams.Split(',').ToList<object>();
            }

            SystemServiceListingEntity systemServiceListingEntity = this.systemServiceListingData.Get(SYSTEM_CONFIGURATION_ID, serviceName);
            if (systemServiceListingEntity == null)
            {
                throw new ArgumentException(string.Format("{0} 服务不存在", serviceName));
            }
            return this.GetServiceMethodExecutionResult(systemServiceListingEntity, paras);
        }
        #endregion

        #region 插入页面附件及构建head区域
        /// <summary>
        /// 插入页面附件及构建head区域
        /// </summary>
        /// <param name="pageTemplateEntity">页面模板信息</param>
        /// <param name="html">页面html</param>
        /// <returns></returns>
        private string SettingHeadAndAppendAttachments(PageTemplateEntity pageTemplateEntity, string html)
        {
            var websiteAttachments = this.websiteTemplateAttachmentService.GetList(pageTemplateEntity.WebsiteTemplateId);
            //开始处理页面附加文件信息
            var attachments = this.pageTemplateAttachmentData.GetList(pageTemplateEntity.PageTemplateId).Result;
            List<string> headCssList = new List<string>();
            List<string> headScriptList = new List<string>();
            List<string> footerCssList = new List<string>();
            List<string> footerScriptList = new List<string>();

            foreach (var item in websiteAttachments.Where(p => p.InsertLocation == StaticPageInsertLocationType.Head))
            {
                if (item.FileType == StaticPageFileType.Css)
                {
                    string css = string.Format("<link rel=\"stylesheet\" href=\"{0}\">", item.FileAddress);
                    headCssList.Add(css);
                }
                else
                {
                    string js = string.Format("<script type=\"text/javascript\" src=\"{0}\">", item.FileAddress);
                    headScriptList.Add(js);
                }
            }
            foreach (var item in websiteAttachments.Where(p => p.InsertLocation == StaticPageInsertLocationType.HtmlEnd))
            {
                if (item.FileType == StaticPageFileType.Css)
                {
                    string css = string.Format("<link rel=\"stylesheet\" href=\"{0}\">", item.FileAddress);
                    footerCssList.Add(css);
                }
                else
                {
                    string js = string.Format("<script type=\"text/javascript\" src=\"{0}\">", item.FileAddress);
                    footerScriptList.Add(js);
                }
            }
            foreach (var item in attachments.Where(p => p.InsertLocation == StaticPageInsertLocationType.Head))
            {
                if (item.FileType == StaticPageFileType.Css)
                {
                    string css = string.Format("<link rel=\"stylesheet\" href=\"{0}\">", item.FileAddress);
                    headCssList.Add(css);
                }
                else
                {
                    string js = string.Format("<script type=\"text/javascript\" src=\"{0}\">", item.FileAddress);
                    headScriptList.Add(js);
                }
            }
            foreach (var item in attachments.Where(p => p.InsertLocation == StaticPageInsertLocationType.HtmlEnd))
            {
                if (item.FileType == StaticPageFileType.Css)
                {
                    string css = string.Format("<link rel=\"stylesheet\" href=\"{0}\">", item.FileAddress);
                    footerCssList.Add(css);
                }
                else
                {
                    string js = string.Format("<script type=\"text/javascript\" src=\"{0}\">", item.FileAddress);
                    footerScriptList.Add(js);
                }
            }

            string htmlHeadTag = this.GetHtmlTag(html, "head");
            string title = string.Empty;
            List<string> metaList = new List<string>();
            List<string> linkList = new List<string>();
            List<string> scriptList = new List<string>();
            List<string> styleList = new List<string>();
            if (!string.IsNullOrWhiteSpace(htmlHeadTag))
            {
                title = GetHtmlTag(htmlHeadTag, "title");
                metaList = GetHtmlTags(htmlHeadTag, "meta");
                linkList = GetHtmlTags(htmlHeadTag, "link");
                scriptList = GetHtmlTags(htmlHeadTag, "script");
                styleList = GetHtmlTags(htmlHeadTag, "style");
            }
            if (!pageTemplateEntity.IsContentPage)
            {
                if (string.IsNullOrWhiteSpace(pageTemplateEntity.ParentPageCode))
                {
                    title = string.Format("{0}-{1}", pageTemplateEntity.PageName, WebsiteConfigurationDto.WebsiteName);
                }
                else
                {
                    title = string.Format("{0}-{1}-{2}", pageTemplateEntity.PageName, pageTemplateEntity.ParentPageName, WebsiteConfigurationDto.WebsiteName);
                }
            }
            else
            {
                title = string.Format("{0}-{1}", pageTemplateEntity.PageName, WebsiteConfigurationDto.WebsiteName);
            }
            List<string> newMetaList = new List<string>();
            if (!metaList.Any(p => p.IndexOf("charset=") > -1))
            {
                newMetaList.Add("<meta charset=\"utf-8\">");
            }
            if (!metaList.Any(p => p.IndexOf("name=\"viewport\"") > -1))
            {
                newMetaList.Add("<meta name=\"viewport\" content=\"width=device-width,initial-scale=1,maximum-scale=1\">");
            }
            if (!metaList.Any(p => p.IndexOf("name=\"keywords\"") > -1))
            {
                newMetaList.Add(string.Format("<meta name=\"keywords\" content=\"{0}\">", pageTemplateEntity.PageKeyword));
            }
            if (!metaList.Any(p => p.IndexOf("name=\"description\"") > -1))
            {
                newMetaList.Add(string.Format("<meta name=\"description\" content=\"{0}\">", pageTemplateEntity.PageDescription));
            }
            newMetaList.AddRange(metaList);
            List<string> pageCssList = new List<string>();
            List<string> pageScriptList = new List<string>();
            foreach (var item in linkList)
            {
                Regex regex = new Regex("href=\"([^\"]+)");
                if (regex.IsMatch(item))
                {
                    string src = regex.Match(item).Groups[1].ToString();
                    if (!headCssList.Any(p => p.IndexOf(src) > -1) && !pageCssList.Any(p => p.IndexOf(src) > -1))
                    {
                        pageCssList.Add(string.Format("<link rel=\"stylesheet\" href=\"{0}\">", src));
                    }
                }
                else
                {
                    pageCssList.Add(item);
                }
            }
            foreach (var item in scriptList)
            {
                Regex regex = new Regex("src=\"([^\"]+)");
                if (regex.IsMatch(item))
                {
                    string src = regex.Match(item).Groups[1].ToString();
                    if (!headScriptList.Any(p => p.IndexOf(src) > -1) && !pageScriptList.Any(p => p.IndexOf(src) > -1))
                    {
                        pageScriptList.Add(string.Format("<script type=\"text/javascript\" src=\"{0}\"></script>", src));
                    }
                }
                else
                {
                    pageScriptList.Add(item);
                }
            }
            for (int i = 0; i < headScriptList.Count; i++)
            {
                if (headScriptList[i].IndexOf("</script>") == -1)
                {
                    string value = string.Format("{0}</script>", headScriptList[i]);
                    headScriptList[i] = value;
                }
            }
            for (int i = 0; i < pageScriptList.Count; i++)
            {
                if (pageScriptList[i].IndexOf("</script>") == -1)
                {
                    string value = string.Format("{0}</script>", pageScriptList[i]);
                    pageScriptList[i] = value;
                }
            }

            StringBuilder newHtmlHeadTag = new StringBuilder("<head>");
            newHtmlHeadTag.Append("\r\n");
            newHtmlHeadTag.AppendJoin("\r\n", newMetaList);
            newHtmlHeadTag.Append("\r\n");
            newHtmlHeadTag.AppendLine(string.Format("<title>{0}</title>", title));
            newHtmlHeadTag.AppendJoin("\r\n", headCssList);
            newHtmlHeadTag.Append("\r\n");
            newHtmlHeadTag.AppendJoin("\r\n", pageCssList);
            newHtmlHeadTag.Append("\r\n");
            newHtmlHeadTag.AppendJoin("\r\n", headScriptList);
            newHtmlHeadTag.Append("\r\n");
            newHtmlHeadTag.AppendJoin("\r\n", pageScriptList);
            newHtmlHeadTag.Append("\r\n");
            newHtmlHeadTag.AppendLine("</head>");
            foreach (var item in styleList)
            {
                newHtmlHeadTag.AppendLine(item);
            }
            if (string.IsNullOrWhiteSpace(htmlHeadTag))
            {
                string preHead = html.Substring(0, html.IndexOf("<body>"));
                string afterHead = html.Substring(html.IndexOf("<body>"));
                html = preHead + newHtmlHeadTag.ToString() + afterHead;
            }
            else
            {
                html = html.Replace(htmlHeadTag, newHtmlHeadTag.ToString());
            }
            StringBuilder sb = new StringBuilder(html);
            foreach (string item in footerCssList)
            {
                sb.AppendLine(item);
            }
            foreach (string item in footerScriptList)
            {
                sb.AppendLine(item);
            }
            return sb.ToString();
        }
        #endregion

        #region 构建静态页面内部处理逻辑

        #region 写入文件
        /// <summary>
        /// 获取父级页面路径
        /// </summary>
        /// <param name="pageTemplateEntity">页面模板信息</param>
        /// <returns></returns>
        private string GetParentPagePath(PageTemplateEntity pageTemplateEntity)
        {
            string path = string.Empty;

            if (pageTemplateEntity.PageLevel > 0)
            {
                path = this.pageTemplateData.GetParentAllPagePath(pageTemplateEntity.PageCode);
            }
            path = path.IndexOf("/") > -1 ? path.Substring(0, path.LastIndexOf("/")) : path;
            string directoryPath = string.Empty;
            DirectoryInfo directoryInfo = Directory.GetParent(Directory.GetCurrentDirectory());
            directoryPath = Path.Combine(directoryInfo.FullName, configuration["WebsiteName"]);
            directoryPath = Path.Combine(directoryPath, path);

            return directoryPath;
        }
        private void SaveHtml(string html, string path, int level, string fileName, int? index)
        {
            string filePath = path;
            string newFileName = fileName;

            if (this.ContentId.HasValue)
            {
                newFileName = string.Concat(fileName, "-", this.ContentId.ToString());
            }
            if (index.HasValue && index.Value > 1)
            {
                newFileName = string.Concat(newFileName, "_", index.Value.ToString());
            }
            newFileName += ".html";
            string fullPath = Path.Combine(filePath, newFileName);
            if (!Directory.Exists(filePath))
            {
                Directory.CreateDirectory(filePath);
            }
            if (File.Exists(fullPath))
            {
                File.Delete(fullPath);
            }
            using (StreamWriter sw = new StreamWriter(fullPath, false))
            {
                sw.WriteLine(html);
                sw.Close();
            }
            if (this.ContentId.HasValue)
            {
                newFileName = fileName+ ".html";
                fullPath = Path.Combine(filePath, newFileName);
                if (!Directory.Exists(filePath))
                {
                    Directory.CreateDirectory(filePath);
                }
                if (File.Exists(fullPath))
                {
                    File.Delete(fullPath);
                }
                using (StreamWriter sw = new StreamWriter(fullPath, false))
                {
                    sw.WriteLine(html);
                    sw.Close();
                }
            }
        }
        #endregion

        #region 解析动态标记码并转换
        /// <summary>
        /// 解析动态标记码并转换
        /// </summary>
        /// <param name="html">页面Html</param>
        /// <returns>返回转换完成的Html</returns>
        private string ParseDynamicTagcode(string html)
        {
            //获取动态标记并替换
            List<string> dynamicTag = this.MatchDynamicTag(html);
            return this.ReplaceDynamicTag(html, dynamicTag);
        }
        #endregion

        #region 解析系统定义标签
        /// <summary>
        /// 解析系统定义标签
        /// </summary>
        /// <param name="html">页面Html</param>
        /// <returns></returns>
        private string ParseSystemDefinedTag(string html)
        {
            List<string> definedTag = this.MatchSystemDefinedTag(html);
            return this.ReplaceSystemDefinedTag(html, definedTag);
        }
        #endregion

        #region 系统标记码处理

        #region 反射系统信息实例获取对象值
        /// <summary>
        /// 反射获取对象值
        /// </summary>
        /// <returns></returns>
        private string ReflectSystemConfigurationInstanceValue(string key)
        {
            key = key.Replace("{{", "").Replace("}}", "").Trim().Replace("$$", "").Trim();
            PropertyInfo[] properties = this.WebsiteConfigurationDto.GetType().GetProperties();

            foreach (PropertyInfo property in properties)
            {
                //Console.WriteLine(property.Name);
                if (property.Name.Equals(key))
                {
                    return property.GetValue(this.WebsiteConfigurationDto, null).ToString();
                }
            }
            return "";
        }
        #endregion

        #region 反射系统预定义标签对象值
        /// <summary>
        /// 反射系统预定义标签对象值
        /// </summary>
        /// <returns></returns>
        private string ReflectSystemDefinedTagValue(string key)
        {
            key = key.Replace("{{", "").Replace("}}", "").Trim().Replace("##", "").Trim();
            switch (key)
            {
                case "pageIndex":
                    return this.PageIndex.ToString();
                case "pageSize":
                    return this.PageSize.ToString();
            }
            return "";
        }
        #endregion

        #region 替换系统预定义标签
        /// <summary>
        /// 替换系统标签
        /// </summary>
        /// <param name="html">html模板</param>
        /// <param name="systemDefinedTag">系统预定义标签列表</param>
        /// <returns></returns>
        private string ReplaceSystemDefinedTag(string html, List<string> systemDefinedTag)
        {
            foreach (string tag in systemDefinedTag)
            {
                html = html.Replace(tag, this.ReflectSystemDefinedTagValue(tag));
            }
            return html;
        }
        #endregion

        #region 替换系统标签
        /// <summary>
        /// 替换系统标签
        /// </summary>
        /// <param name="html">html模板</param>
        /// <param name="systemTag">系统标签列表</param>
        /// <returns></returns>
        private string ReplaceSystemTag(string html, List<string> systemTag)
        {
            foreach (string tag in systemTag)
            {
                html = html.Replace(tag, this.ReflectSystemConfigurationInstanceValue(tag));
            }
            return html;
        }
        #endregion

        #endregion

        #region 替换动态标签
        private string ReplaceDynamicTag(string html, List<string> dynamicTag)
        {
            foreach (string tag in dynamicTag)
            {
                html = ReplaceInlineDynamicTag(html, tag);
            }
            return html;
        }

        #region 查找动态标签
        /// <summary>
        /// 查找动态标签
        /// </summary>
        /// <param name="html">页面html</param>
        /// <param name="template">提取的标签模板</param>
        /// <param name="systemTagName">需要提取的内容标签名称</param>
        /// <returns></returns>
        private string ReplaceSystemTagTemplateInlineDynamicTag(string html, string template, string systemTagName)
        {
            List<object> paras = new List<object>();
            Regex beginRegex = new Regex("[{]{2}\\s*(" + systemTagName + ")[^}]*\\s*[}]{2}");
            MatchCollection matchCollection = beginRegex.Matches(html);
            string beginTemplate = matchCollection.AsEnumerable<Match>().FirstOrDefault().Value;
            string serviceName = beginTemplate.Replace(systemTagName, "").Replace("{{", "").Replace("}}", "").Trim();

            Regex regex = new Regex("[(]{1}[\\s]*[a-zA-Z0-9_,?\"\\s]*[)]{1}");
            Match match = regex.Match(serviceName);
            if (match.Success)
            {
                serviceName = serviceName.Substring(0, serviceName.IndexOf('('));
                string value = match.Value.Replace("(", "").Replace(")", "");
                while (value.IndexOf(" ") > -1)
                {
                    value = value.Replace(" ", "");
                }
                string[] strParams = value.Split(',');
                for (int i = 0; i < strParams.Length; i++)
                {
                    paras.Add(strParams[i]);
                }
            }

            if (this.PageTemplateEntity != null && this.IsPagingListPage&&systemTagName=="BCPagingTag")
            {
                paras = this.PageTemplateEntity.PagingListServiceParams.Split(",").ToList<object>();
            }


            SystemServiceListingEntity systemServiceListingEntity = this.systemServiceListingData.Get(SYSTEM_CONFIGURATION_ID, serviceName);
            if (systemServiceListingEntity == null)
            {
                throw new ArgumentException(string.Format("{0} 服务不存在", serviceName));
            }
            string templateHtmlResult = this.ReplaceSampleTag(systemServiceListingEntity, paras, template);

            return html.Replace(template, templateHtmlResult);
        }
        /// <summary>
        /// 查找对象标签
        /// </summary>
        /// <param name="html">页面html</param>
        /// <param name="template">提取的标签模板</param>
        /// <param name="systemTagName">需要提取的内容标签名称</param>
        /// <returns></returns>
        private string ReplaceSystemTagTemplateInlineObjectTag(string html, string template, string systemTagName)
        {
            List<object> paras = new List<object>();
            Regex templateRegex = GetNestedTagRegex(systemTagName);
            //new Regex("[{]{2}[\\s]*(" + systemTagName + "){1}[\\s]+([a-zA-Z0-9_]+)[(]{1}([\\s\\S\\n](?<!(##}})))+");
            Regex beginRegex = new Regex("([{]{2}[\\s]*(" + systemTagName + "){1}[^}]*\\s*[}]{2})");
            MatchCollection matchTemplateCollection = templateRegex.Matches(html);
            MatchCollection matchCollection = beginRegex.Matches(matchTemplateCollection.AsEnumerable<Match>().FirstOrDefault().Value);
            string beginTemplate = matchCollection.AsEnumerable<Match>().FirstOrDefault().Value;
            string serviceName = beginTemplate.Replace(systemTagName, "").Replace("{{", "").Replace("}}", "").Trim();

            Regex regex = new Regex("[(]{1}[\\s]*[a-zA-Z0-9_,?\"\\s]*[)]{1}");
            Match match = regex.Match(serviceName);
            if (match.Success)
            {
                serviceName = serviceName.Substring(0, serviceName.IndexOf('('));
                string value = match.Value.Replace("(", "").Replace(")", "");
                while (value.IndexOf(" ") > -1)
                {
                    value = value.Replace(" ", "");
                }
                string[] strParams = value.Split(',');
                for (int i = 0; i < strParams.Length; i++)
                {
                    paras.Add(strParams[i]);
                }
            }

            SystemServiceListingEntity systemServiceListingEntity = this.systemServiceListingData.Get(SYSTEM_CONFIGURATION_ID, serviceName);
            string templateHtmlResult = this.ReplaceSampleTag(systemServiceListingEntity, paras, template);

            return html.Replace(template, templateHtmlResult);
        }
        #endregion

        #region 查找内嵌动态标签

        private string ReplaceInlineDynamicTag(string html, string tag)
        {
            List<object> parameters = new List<object>();
            string currentTag = tag.Replace("{{", "").Replace("}}", "").Replace("!!", "");

            if (currentTag.Equals("CurrentPagePrimaryKey"))
            {
                return html.Replace(tag, this.ContentId.ToString());
            }
            TemplateTagEntity templateTagEntity = templateTagData.GetTemplateTagEntity(currentTag);

            if (templateTagEntity == null)
            {
                throw new ArgumentException(string.Format("不存在模板标记码 {0}。", tag));
            }
            return html.Replace(tag, templateTagEntity.TagValue);
        }
        #endregion
        #endregion

        #region 替换模板标签样本
        /// <summary>
        /// 替换模板标签样本
        /// </summary>
        /// <param name="systemServiceListingEntity">系统服务列表实体</param>
        /// <param name="parameterArr">动态参数</param>
        /// <param name="tagHtml">标签</param>
        /// <returns></returns>
        private string ReplaceSampleTag(SystemServiceListingEntity systemServiceListingEntity, List<object> parameterArr, string tagHtml)
        {
            string html = string.Empty;
            object result = this.GetServiceMethodExecutionResult(systemServiceListingEntity, parameterArr);
            
            switch (systemServiceListingEntity.ResultType)
            {
                case StaticPageResultType.Object:
                    html = this.ParseObjectTemplateResult(result, tagHtml);
                    break;
                case StaticPageResultType.Value:
                    html = result.ToString();
                    break;
                case StaticPageResultType.Array:
                    dynamic dynamicArr = result;
                    if (!string.IsNullOrWhiteSpace(tagHtml))
                    {
                        html = ParseForTemplateArrayResult(tagHtml, dynamicArr, null);
                    }
                    break;
                case StaticPageResultType.PageableList:
                    dynamic dynamicObj = result;
                    if (!string.IsNullOrWhiteSpace(tagHtml))
                    {
                        html = ParsePageableTemplateResult(tagHtml, dynamicObj.Items, dynamicObj.Count, dynamicObj.PageIndex, dynamicObj.PageSize, systemServiceListingEntity.ResultEntityName);
                    }
                    break;
                default:
                    break;
            }
            return html;
        }

        #region 获取服务方法结果
        /// <summary>
        /// 获取服务方法结果
        /// </summary>
        /// <param name="systemServiceListingEntity">系统服务列表实体</param>
        /// <param name="parameterArr">动态参数</param>
        /// <returns></returns>
        private object GetServiceMethodExecutionResult(SystemServiceListingEntity systemServiceListingEntity, List<object> parameterArr)
        {
            //序列化服务调用参数对象
            Dictionary<string, object> dictionary = new Dictionary<string, object>();
            if (!string.IsNullOrWhiteSpace(systemServiceListingEntity.ParamsText))
            {
                string[] paramsTemplate = systemServiceListingEntity.ParamsText.Replace("(", "").Replace(")", "").Split(',');
                if (systemServiceListingEntity.ResultType == StaticPageResultType.PageableList)
                {
                    if(paramsTemplate.Length == parameterArr.Count)
                    {
                        for (int i = 0; i < paramsTemplate.Length; i++)
                        {
                            string paramsName = paramsTemplate[i].Trim().Split(' ')[1].Trim();
                            dictionary.Add(paramsName, parameterArr[i]);
                        }
                    }
                    else
                    {
                        if (paramsTemplate.Length != parameterArr.Count + 2)
                        {
                            throw new ArgumentException(systemServiceListingEntity.MethodName + "参数位数不正确，请检查是否有遗漏。");
                        }
                        for (int i = 0; i < paramsTemplate.Length; i++)
                        {
                            string paramsName = paramsTemplate[i].Trim().Split(' ')[1].Trim();
                            if (i + 2 == paramsTemplate.Length)
                            {
                                dictionary.Add("pageIndex", this.PageIndex);
                                dictionary.Add("pageSize", this.PageSize);
                                break;
                            }
                            else
                            {
                                dictionary.Add(paramsName, parameterArr[i]);
                            }
                        }
                    }
                }
                else
                {
                    if (paramsTemplate.Length != parameterArr.Count)
                    {
                        throw new ArgumentException(systemServiceListingEntity.MethodName + "参数位数不正确，请检查是否有遗漏。");
                    }
                    for (int i = 0; i < paramsTemplate.Length; i++)
                    {
                        string paramsName = paramsTemplate[i].Trim().Split(' ')[1].Trim();
                        dictionary.Add(paramsName, parameterArr[i]);
                    }
                }
            }


            //开始构建动态服务
            Type type = Type.GetType(systemServiceListingEntity.ServiceName);

            ConstructorInfo firstConstructor = type.GetTypeInfo().GetConstructors().FirstOrDefault();
            //获取构造参数列表最多的构造方法
            foreach (var constructor in type.GetTypeInfo().GetConstructors())
            {
                if (constructor.GetParameters().Length > firstConstructor.GetParameters().Length)
                {
                    firstConstructor = constructor;
                }
            }
            //提取构造参数
            IEnumerable<object> constructorParameters = firstConstructor.GetParameters().Select(p => serviceProvider.GetService(p.ParameterType));
            //构建服务实例
            var service = Activator.CreateInstance(type, constructorParameters.ToArray());
            //构建服务方法
            MethodInfo method = type.GetMethod(systemServiceListingEntity.MethodName);
            if (method == null)
            {
                throw new ArgumentException("系统不存在此方法，请检查服务命名空间及方法名称是否正确！");
            }
            //提取服务方法调用参数列表
            ParameterInfo[] parameters = method.GetParameters();
            List<object> requestParams = new List<object>();
            if (parameters.Any())
            {
                if (!parameterArr.Any())
                {
                    foreach (ParameterInfo parameter in parameters)
                    {
                        if (dictionary.TryGetValue(parameter.Name, out object value))
                        {
                            requestParams.Add(Convert.ChangeType(value, parameter.ParameterType));
                        }
                        else
                        {
                            if (parameter.ParameterType.Name.Equals("String"))
                            {
                                requestParams.Add("");
                            }
                            else if (parameter.ParameterType.IsGenericType && parameter.ParameterType.GetGenericTypeDefinition().Equals(typeof(Nullable<>)))
                            {
                                requestParams.Add(null);
                            }
                            else
                            {
                                requestParams.Add(parameter.RawDefaultValue);
                            }
                        }
                    }
                }
                else
                {
                    for (int i = 0; i < dictionary.Count; i++)
                    {
                        var obj = dictionary.ElementAt(i);
                        if (parameters[i].ParameterType.Name == "Nullable`1")
                        {
                            if (obj.Value.ToString().Trim().ToLower() != "null" && obj.Value.ToString().Trim() != "")
                            {
                                if (parameters[i].ParameterType.GenericTypeArguments.Length > 0)
                                {
                                    requestParams.Add(Convert.ChangeType(obj.Value, parameters[i].ParameterType.GenericTypeArguments[0]));
                                }
                            }
                            else
                            {
                                requestParams.Add(null);
                            }
                        }
                        else
                        {
                            if (obj.Value.ToString().Trim() == "null")
                            {
                                if (parameters[i].ParameterType.Name == "String")
                                {
                                    requestParams.Add("");
                                }
                                else
                                {
                                    requestParams.Add(null);
                                }
                            }
                            else if (obj.Value.ToString().IndexOf("\"") > -1)
                            {
                                while (obj.Value.ToString().IndexOf("\"") > -1)
                                {
                                    requestParams.Add(obj.Value.ToString().Replace("\"", ""));
                                }
                                if (string.IsNullOrWhiteSpace(obj.Value.ToString()))
                                {
                                    if (parameters[i].ParameterType.Name == "String")
                                    {
                                        requestParams.Add("");
                                    }
                                    else
                                    {
                                        requestParams.Add(null);
                                    }
                                }
                                else
                                {
                                    requestParams.Add(Convert.ChangeType(obj.Value, parameters[i].ParameterType));
                                }
                            }
                            else
                            {
                                requestParams.Add(Convert.ChangeType(obj.Value, parameters[i].ParameterType));
                            }
                        }
                    }
                }
            }
            object result = method.Invoke(service, requestParams.ToArray());
            return result;
        }
        #endregion

        #region 解析Pageable分页模板对象，并替换样本
        /// <summary>
        /// 解析Pageable分页模板对象，并替换样本
        /// </summary>
        /// <param name="pageTemplate">Pageable模板html</param>
        /// <param name="array">方法调用返回值数组对象</param>
        /// <param name="count">总数据量</param>
        /// <param name="pageIndex">当前页码</param>
        /// <param name="pageSize">每页数据条数</param>
        /// <param name="entityName">数据实体对象名称（Dto名称）</param>
        /// <returns></returns>
        private string ParsePageableTemplateResult(string pageTemplate, IEnumerable<object> array, long? count, int pageIndex, int pageSize, string entityName)
        {
            long currentlyPageNumber = pageIndex <= 1 ? 1 : pageIndex + 1;
            long totalPageNumber = count.HasValue && count.Value > 0 ? count.Value % pageSize > 0 ? count.Value / pageSize + 1 : count.Value / pageSize : 0;
            string html = pageTemplate;
            Regex beginRegex = new Regex("([{]{2}[\\s]*(BCPagingTag){1}[^}]*[\\s]*[}]{2})");
            Regex endRegex = new Regex("([{]{2}[/]{1}[\\s]*(BCPagingTag){1}[^}]*[\\s]*[}]{2})");

            Regex pageContentTemplateRegex = GetNestedTagRegex("BCTemplate");
            Regex pageContentTemplateBeginRegex = new Regex("[{]{2}[\\s]*(BCTemplate)[^}]*[\\s]*[}]{2}");
            Regex pageContentTemplateEndRegex = new Regex("([{]{2}[/]{1}[\\s]*(BCTemplate)[^}]*[\\s]*[}]{2})");

            Regex pagingTemplateRegex = GetNestedTagRegex("BCPagingTemplate");
            Regex pagingTemplateBeginRegex = new Regex("[{]{2}[\\s]*(BCPagingTemplate)[^}]*[\\s]*[}]{2}");
            Regex pagingTemplateEndRegex = new Regex("([{]{2}[/]{1}[\\s]*(BCPagingTemplate)[^}]*[\\s]*[}]{2})");

            Regex pagingPreviousTemplateRegex = GetNestedTagRegex("BCPagingPreviousTemplate");
            Regex pagingPreviousTemplateBeginRegex = new Regex("[{]{2}[\\s]*(BCPagingPreviousTemplate)[^}]*[\\s]*[}]{2}");
            Regex pagingPreviousTemplateEndRegex = new Regex("([{]{2}[/]{1}[\\s]*(BCPagingPreviousTemplate)[^}]*[\\s]*[}]{2})");

            Regex pagingNextTemplateRegex = GetNestedTagRegex("BCPagingNextTemplate");
            Regex pagingNextTemplateBeginRegex = new Regex("[{]{2}[\\s]*(BCPagingNextTemplate)[^}]*[\\s]*[}]{2}");
            Regex pagingNextTemplateEndRegex = new Regex("([{]{2}[/]{1}[\\s]*(BCPagingNextTemplate)[^}]*[\\s]*[}]{2})");

            Regex pagingListTemplateRegex = GetNestedTagRegex("BCPagingListTemplate");
            Regex pagingListTemplateBeginRegex = new Regex("[{]{2}[\\s]*(BCPagingListTemplate)[^}]*[\\s]*[}]{2}");
            Regex pagingListTemplateEndRegex = new Regex("([{]{2}[/]{1}[\\s]*(BCPagingListTemplate)[^}]*[\\s]*[}]{2})");

            Regex pagingListDefaultTemplateRegex = GetNestedTagRegex("BCPagingListDefaultTemplate");
            Regex pagingListDefaultTemplateBeginRegex = new Regex("[{]{2}[\\s]*(BCPagingListDefaultTemplate)[^}]*[\\s]*[}]{2}");
            Regex pagingListDefaultTemplateEndRegex = new Regex("([{]{2}[/]{1}[\\s]*(BCPagingListDefaultTemplate)[^}]*[\\s]*[}]{2})");

            Regex pagingListActiveTemplateRegex = GetNestedTagRegex("BCPagingListActiveTemplate");
            Regex pagingListActiveTemplateBeginRegex = new Regex("[{]{2}[\\s]*(BCPagingListActiveTemplate)[^}]*[\\s]*[}]{2}");
            Regex pagingListActiveTemplateEndRegex = new Regex("([{]{2}[/]{1}[\\s]*(BCPagingListActiveTemplate)[^}]*[\\s]*[}]{2})");

            Regex previousPageIndexRegex = new Regex("[{]{2}[\\s]*[$]{2}(previousPageIndex)[\\s]*[}]{2}");
            Regex nextPageIndexRegex = new Regex("[{]{2}[\\s]*[$]{2}(nextPageIndex)[\\s]*[}]{2}");

            Match match = beginRegex.Match(pageTemplate);
            string beginTemplate = string.Empty;
            if (match.Success)
            {
                beginTemplate = match.Value;
            }
            else
            {
                throw new ArgumentException("分页模板--模板处理中：\r\n获取模板整体标记开头部分失败，请检查标签是否正确");
            }
            match = endRegex.Match(pageTemplate);
            string endTemplate = string.Empty;
            if (match.Success)
            {
                endTemplate = match.Value;
            }
            else
            {
                throw new ArgumentException("分页模板--模板处理中：\r\n获取模板整体标记结尾部分失败，请检查标签是否正确");
            }
            html = html.Replace(beginTemplate, "");
            html = html.Replace(endTemplate, "");

            #region 分页模板内容模板处理
            //分页模板--内容列表模板处理
            string pageContentHtml = string.Empty;
            match = pageContentTemplateRegex.Match(html);
            if (match.Success)
            {
                pageContentHtml = match.Value;
            }
            else
            {
                throw new ArgumentException("分页模板--内容列表模板处理中：\r\n获取标签内容失败，请检查标签是否正确");
            }
            //截取模板标记开头部分
            string pageContentBeginHtml = string.Empty;
            match = pageContentTemplateBeginRegex.Match(pageContentHtml);
            if (match.Success)
            {
                pageContentBeginHtml = match.Value;
            }
            else
            {
                throw new ArgumentException("分页模板--内容列表模板处理中：\r\n截取模板标记开头部分失败，请检查标签是否正确");
            }
            //截取模板标记结尾部分
            string pageContentEndHtml = string.Empty;
            match = pageContentTemplateEndRegex.Match(pageContentHtml);
            if (match.Success)
            {
                pageContentEndHtml = match.Value;
            }
            else
            {
                throw new ArgumentException("分页模板--内容列表模板处理中：\r\n截取模板标记结尾部分失败，请检查标签是否正确");
            }
            //移除模板标记开头与结尾
            string pageContentResultHtml = pageContentHtml.Replace(pageContentBeginHtml, "");
            pageContentResultHtml = pageContentResultHtml.Replace(pageContentEndHtml, "");

            //获取内容部分模板，并转换模板中的标签
            string pageContentResultElementHtml = string.Empty;
            foreach (object obj in array)
            {
                pageContentResultElementHtml += this.MakeResultObject(obj, pageContentResultHtml);
            }
            html = html.Replace(pageContentHtml, pageContentResultElementHtml);
            #endregion

            #region 处理分页页码标签模板
            //处理分页页码标签模板
            string pagingTemplate = string.Empty;
            match = pagingTemplateRegex.Match(html);
            if (match.Success)
            {
                pagingTemplate = match.Value;
            }
            else
            {
                throw new ArgumentException("分页模板--分页页码标签模板处理中：\r\n获取分页页码标签模板失败，请检查标签是否正确");
            }
            //截取分页页码标签模板标记开头部分
            string pagingTemplateBeginHtml = string.Empty;
            match = pagingTemplateBeginRegex.Match(pagingTemplate);
            if (match.Success)
            {
                pagingTemplateBeginHtml = match.Value;
            }
            else
            {
                throw new ArgumentException("分页模板--内容列表模板处理中：\r\n截取模板标记开头部分失败，请检查标签是否正确");
            }
            //截取模板标记结尾部分
            string pagingTemplateEndHtml = string.Empty;
            match = pagingTemplateEndRegex.Match(pagingTemplate);
            if (match.Success)
            {
                pagingTemplateEndHtml = match.Value;
            }
            else
            {
                throw new ArgumentException("分页模板--内容列表模板处理中：\r\n截取模板标记结尾部分失败，请检查标签是否正确");
            }
            //移除模板标记开头与结尾
            string pagingTemplateResultHtml = pagingTemplate.Replace(pagingTemplateBeginHtml, "");
            pagingTemplateResultHtml = pagingTemplateResultHtml.Replace(pagingTemplateEndHtml, "");

            #region 处理上一步分页模板
            //分页模板--分页器上一步模板处理
            string previousTemplateHtml = string.Empty;
            match = pagingPreviousTemplateRegex.Match(pagingTemplateResultHtml);
            if (match.Success)
            {
                previousTemplateHtml = match.Value;
            }
            else
            {
                throw new ArgumentException("分页模板--分页器上一步模板处理中：\r\n获取标签内容失败，请检查标签是否正确");
            }
            if (currentlyPageNumber > 1)
            {
                //截取分页器上一步模板标记开头部分
                string previousTemplateBeginHtml = string.Empty;
                match = pagingPreviousTemplateBeginRegex.Match(previousTemplateHtml);
                if (match.Success)
                {
                    previousTemplateBeginHtml = match.Value;
                }
                else
                {
                    throw new ArgumentException("分页模板--分页器上一步模板处理中：\r\n截取分页器上一步模板标记开头部分失败，请检查标签是否正确");
                }
                //截取分页器上一步模板标记结尾部分
                string previousTemplateEndHtml = string.Empty;
                match = pagingPreviousTemplateEndRegex.Match(previousTemplateHtml);
                if (match.Success)
                {
                    previousTemplateEndHtml = match.Value;
                }
                else
                {
                    throw new ArgumentException("分页模板--分页器上一步模板处理中：\r\n截取分页器上一步模板标记结尾部分失败，请检查标签是否正确");
                }
                //移除模板标记开头与结尾
                string previousTemplateResultHtml = previousTemplateHtml.Replace(previousTemplateBeginHtml, "");
                previousTemplateResultHtml = previousTemplateResultHtml.Replace(previousTemplateEndHtml, "");


                match = previousPageIndexRegex.Match(previousTemplateResultHtml);
                if (match.Success)
                {
                    previousTemplateResultHtml = previousTemplateResultHtml.Replace(match.Value, "上一页");

                    pagingTemplateResultHtml = pagingTemplateResultHtml.Replace(previousTemplateHtml, previousTemplateResultHtml);
                }
            }
            else
            {
                pagingTemplateResultHtml = pagingTemplateResultHtml.Replace(previousTemplateHtml, "");
            }

            #endregion

            #region 处理下一步分页模板
            //分页模板--分页器下一步模板处理
            string nextTemplateHtml = string.Empty;
            match = pagingNextTemplateRegex.Match(pagingTemplateResultHtml);
            if (match.Success)
            {
                nextTemplateHtml = match.Value;
            }
            else
            {
                throw new ArgumentException("分页模板--分页器下一步模板处理中：\r\n获取标签内容失败，请检查标签是否正确");
            }
            if (currentlyPageNumber < totalPageNumber)
            {
                //截取分页器下一步模板标记开头部分
                string nextTemplateBeginHtml = string.Empty;
                match = pagingNextTemplateBeginRegex.Match(nextTemplateHtml);
                if (match.Success)
                {
                    nextTemplateBeginHtml = match.Value;
                }
                else
                {
                    throw new ArgumentException("分页模板--分页器下一步模板处理中：\r\n截取分页器下一步模板标记开头部分失败，请检查标签是否正确");
                }
                //截取分页器下一步模板标记结尾部分
                string nextTemplateEndHtml = string.Empty;
                match = pagingNextTemplateEndRegex.Match(nextTemplateHtml);
                if (match.Success)
                {
                    nextTemplateEndHtml = match.Value;
                }
                else
                {
                    throw new ArgumentException("分页模板--分页器下一步模板处理中：\r\n截取分页器下一步模板标记结尾部分失败，请检查标签是否正确");
                }
                //移除模板标记开头与结尾
                string nextTemplateResultHtml = nextTemplateHtml.Replace(nextTemplateBeginHtml, "");
                nextTemplateResultHtml = nextTemplateResultHtml.Replace(nextTemplateEndHtml, "");

                match = nextPageIndexRegex.Match(nextTemplateResultHtml);
                if (match.Success)
                {
                    nextTemplateResultHtml = nextTemplateResultHtml.Replace(match.Value, "下一页");
                    pagingTemplateResultHtml = pagingTemplateResultHtml.Replace(nextTemplateHtml, nextTemplateResultHtml);
                }
            }
            else
            {
                pagingTemplateResultHtml = pagingTemplateResultHtml.Replace(nextTemplateHtml, "");
            }
            #endregion

            #region 处理分页模板中页码列表
            //分页模板--页码列表处理
            string pagingListTemplateHtml = string.Empty;
            match = pagingListTemplateRegex.Match(pagingTemplateResultHtml);
            if (match.Success)
            {
                pagingListTemplateHtml = match.Value;
            }
            else
            {
                throw new ArgumentException("分页模板--页码列表处理中：\r\n获取标签内容失败，请检查标签是否正确");
            }
            //截取分页器页码列表模板标记开头部分
            string pagingListTemplateBeginHtml = string.Empty;
            match = pagingListTemplateBeginRegex.Match(pagingListTemplateHtml);
            if (match.Success)
            {
                pagingListTemplateBeginHtml = match.Value;
            }
            else
            {
                throw new ArgumentException("分页模板--页码列表处理中：\r\n截取分页器页码列表模板标记开头部分失败，请检查标签是否正确");
            }
            //截取分页器页码列表模板标记结尾部分
            string pagingListTemplateEndHtml = string.Empty;
            match = pagingListTemplateEndRegex.Match(pagingListTemplateHtml);
            if (match.Success)
            {
                pagingListTemplateEndHtml = match.Value;
            }
            else
            {
                throw new ArgumentException("分页模板--页码列表处理中：\r\n截取分页器页码列表模板标记结尾部分失败，请检查标签是否正确");
            }
            //移除模板标记开头与结尾
            string pagingListTemplateResultHtml = pagingListTemplateHtml.Replace(pagingListTemplateBeginHtml, "");
            pagingListTemplateResultHtml = pagingListTemplateResultHtml.Replace(pagingListTemplateEndHtml, "");
            #endregion

            #region 处理页码列表非当前页模板
            //分页模板--页码列表非当前页模板
            string pagingListDefaultTemplateHtml = string.Empty;
            match = pagingListDefaultTemplateRegex.Match(pagingListTemplateResultHtml);
            if (match.Success)
            {
                pagingListDefaultTemplateHtml = match.Value;
            }
            else
            {
                throw new ArgumentException("分页模板--页码列表处理中：\r\n获取非当前页标签内容失败，请检查标签是否正确");
            }
            //截取分页器页码列表非当前页模板标记开头部分
            string pagingListDefaultTemplateBeginHtml = string.Empty;
            match = pagingListDefaultTemplateBeginRegex.Match(pagingListDefaultTemplateHtml);
            if (match.Success)
            {
                pagingListDefaultTemplateBeginHtml = match.Value;
            }
            else
            {
                throw new ArgumentException("分页模板--页码列表处理中：\r\n截取分页器页码列表非当前页模板标记开头部分失败，请检查标签是否正确");
            }
            //截取分页器页码列表非当前页模板标记结尾部分
            string pagingListDefaultTemplateEndHtml = string.Empty;
            match = pagingListDefaultTemplateEndRegex.Match(pagingListDefaultTemplateHtml);
            if (match.Success)
            {
                pagingListDefaultTemplateEndHtml = match.Value;
            }
            else
            {
                throw new ArgumentException("分页模板--页码列表处理中：\r\n截取分页器页码列表非当前页模板标记结尾部分失败，请检查标签是否正确");
            }
            //移除模板标记开头与结尾
            string pagingListDefaultTemplateResultHtml = pagingListDefaultTemplateHtml.Replace(pagingListDefaultTemplateBeginHtml, "");
            pagingListDefaultTemplateResultHtml = pagingListDefaultTemplateResultHtml.Replace(pagingListDefaultTemplateEndHtml, "");
            #endregion

            #region 处理页码列表当前页模板
            //分页模板--页码列表当前页模板
            string pagingListActiveTemplateHtml = string.Empty;
            match = pagingListActiveTemplateRegex.Match(pagingListTemplateResultHtml);
            if (match.Success)
            {
                pagingListActiveTemplateHtml = match.Value;
            }
            else
            {
                throw new ArgumentException("分页模板--页码列表处理中：\r\n获取当前页标签内容失败，请检查标签是否正确");
            }
            //截取分页器页码列表非当前页模板标记开头部分
            string pagingListActiveTemplateBeginHtml = string.Empty;
            match = pagingListActiveTemplateBeginRegex.Match(pagingListActiveTemplateHtml);
            if (match.Success)
            {
                pagingListActiveTemplateBeginHtml = match.Value;
            }
            else
            {
                throw new ArgumentException("分页模板--页码列表处理中：\r\n截取分页器页码列表当前页模板标记开头部分失败，请检查标签是否正确");
            }
            //截取分页器页码列表非当前页模板标记结尾部分
            string pagingListActiveTemplateEndHtml = string.Empty;
            match = pagingListActiveTemplateEndRegex.Match(pagingListActiveTemplateHtml);
            if (match.Success)
            {
                pagingListActiveTemplateEndHtml = match.Value;
            }
            else
            {
                throw new ArgumentException("分页模板--页码列表处理中：\r\n截取分页器页码列表当前页模板标记结尾部分失败，请检查标签是否正确");
            }
            //移除模板标记开头与结尾
            string pagingListActiveTemplateResultHtml = pagingListActiveTemplateHtml.Replace(pagingListActiveTemplateBeginHtml, "");
            pagingListActiveTemplateResultHtml = pagingListActiveTemplateResultHtml.Replace(pagingListActiveTemplateEndHtml, "");
            #endregion

            #region 构建分页页码标签列表
            if (count > 0)
            {
                if (currentlyPageNumber >= totalPageNumber)
                {
                    currentlyPageNumber = totalPageNumber;
                }
                string resultPagingListTemplateHtml = string.Empty;
                if (totalPageNumber <= 5)
                {
                    for (int i = 1; i <= totalPageNumber; i++)
                    {
                        if (i == currentlyPageNumber)
                        {
                            resultPagingListTemplateHtml += pagingListActiveTemplateResultHtml.Replace("{{$$pageIndex}}", i.ToString());
                        }
                        else
                        {
                            resultPagingListTemplateHtml += pagingListDefaultTemplateResultHtml.Replace("{{$$pageIndex}}", i.ToString());
                        }
                    }
                }
                else
                {
                    if (pageIndex <= 5)
                    {
                        for (int i = 1; i <= 5; i++)
                        {
                            if (i == currentlyPageNumber)
                            {
                                resultPagingListTemplateHtml += pagingListActiveTemplateResultHtml.Replace("{{$$pageIndex}}", i.ToString());
                            }
                            else
                            {
                                resultPagingListTemplateHtml += pagingListDefaultTemplateResultHtml.Replace("{{$$pageIndex}}", i.ToString());
                            }
                        }
                        resultPagingListTemplateHtml += pagingListDefaultTemplateResultHtml.Replace("{{$$pageIndex}}", "•••");
                        resultPagingListTemplateHtml += pagingListDefaultTemplateResultHtml.Replace("{{$$pageIndex}}", totalPageNumber.ToString());
                    }
                    else if (currentlyPageNumber > 5 && currentlyPageNumber + 4 < totalPageNumber)
                    {
                        resultPagingListTemplateHtml += pagingListDefaultTemplateResultHtml.Replace("{{$$pageIndex}}", "•••");
                        for (long i = currentlyPageNumber - 2; i <= currentlyPageNumber + 2; i++)
                        {
                            if (i == currentlyPageNumber)
                            {
                                resultPagingListTemplateHtml += pagingListActiveTemplateResultHtml.Replace("{{$$pageIndex}}", i.ToString());
                            }
                            else
                            {
                                resultPagingListTemplateHtml += pagingListDefaultTemplateResultHtml.Replace("{{$$pageIndex}}", i.ToString());
                            }
                        }
                        resultPagingListTemplateHtml += pagingListDefaultTemplateResultHtml.Replace("{{$$pageIndex}}", "•••");
                        resultPagingListTemplateHtml += pagingListDefaultTemplateResultHtml.Replace("{{$$pageIndex}}", totalPageNumber.ToString());
                    }
                    else if (currentlyPageNumber + 4 >= totalPageNumber)
                    {
                        resultPagingListTemplateHtml += pagingListDefaultTemplateResultHtml.Replace("{{$$pageIndex}}", "•••");
                        for (long i = totalPageNumber - 5; i <= totalPageNumber; i++)
                        {
                            if (i == currentlyPageNumber)
                            {
                                resultPagingListTemplateHtml += pagingListActiveTemplateResultHtml.Replace("{{$$pageIndex}}", i.ToString());
                            }
                            else
                            {
                                resultPagingListTemplateHtml += pagingListDefaultTemplateResultHtml.Replace("{{$$pageIndex}}", i.ToString());
                            }
                        }
                    }
                }
                pagingTemplateResultHtml = pagingTemplateResultHtml.Replace(pagingListTemplateHtml, resultPagingListTemplateHtml);
            }
            else
            {
                pagingTemplateResultHtml = pagingTemplateResultHtml.Replace(pagingListTemplateHtml, "");
            }
            #endregion

            html = html.Replace(pagingTemplate, pagingTemplateResultHtml);

            #endregion

            return html;
        }
        /// <summary>
        /// 获取成对标签正则表达式
        /// </summary>
        /// <param name="nestedTag">嵌套标签</param>
        /// <returns></returns>
        private Regex GetNestedTagRegex(string nestedTag)
        {
            return new Regex("[{]{2}\\s*(?<TemplateTag>" + nestedTag + ")[^}]*\\s*[}]{2}((?<Nested>[{]{2}\\s*\\k<TemplateTag>[^}]*[}]{2})|[{]{2}/\\s*\\k<TemplateTag>\\s*[}]{2}(?<-Nested>)|.*?)*[{]{2}/\\s*\\k<TemplateTag>\\s*[}]{2}", RegexOptions.IgnoreCase | RegexOptions.Multiline | RegexOptions.Singleline);
        }
        #endregion

        #region 解析for循环模板数组对象，并替换样本
        /// <summary>
        /// 解析数组对象，并替换样本
        /// </summary>
        /// <param name="forTemplate">for循环模板html</param>
        /// <param name="array">方法调用返回值数组对象</param>
        /// <param name="count">总数据量</param>
        /// <returns></returns>
        private string ParseForTemplateArrayResult(string forTemplate, IEnumerable<object> array, long? count)
        {
            Regex beginRegex = new Regex("([{]{2}[\\s]*(BCFor){1}[^}]*\\s*[}]{2})");
            Regex endRegex = new Regex("([{]{2}[/]{1}[\\s]*(BCFor){1}[\\s]*[}]{2})");
            MatchCollection matchCollection = beginRegex.Matches(forTemplate);
            if (matchCollection.Count > 0)
            {
                string beginTemplate = matchCollection.AsEnumerable<Match>().FirstOrDefault().Value;
                matchCollection = endRegex.Matches(forTemplate);
                string endTemplate = matchCollection.AsEnumerable<Match>().FirstOrDefault().Value;
                forTemplate = forTemplate.Replace(beginTemplate, "");
                forTemplate = forTemplate.Replace(endTemplate, "");

                string html = string.Empty;
                int index = 1;
                foreach (object obj in array)
                {
                    html += this.MakeResultObject(obj, forTemplate);
                    index++;
                }
                return html;
            }
            else
            {
                return "";
            }
        }
        #endregion

        #region 解析Content模板对象，并替换样本
        /// <summary>
        /// 解析Content模板对象，并替换样本
        /// </summary>
        /// <param name="contentTemplate">Content模板html</param>
        /// <param name="obj">数据对象</param>
        /// <returns></returns>
        private string ParseContentTemplateResult(object obj, string contentTemplate)
        {
            Regex beginRegex = new Regex("([{]{2}[\\s]*(BCContentTag){1}[^}]*\\s*[}]{2})");
            Regex endRegex = new Regex("([{]{2}[/]{1}[\\s]*(BCContentTag){1}[\\s]*[}]{2})");
            MatchCollection matchCollection = beginRegex.Matches(contentTemplate);
            if (matchCollection.Count > 0)
            {
                string beginTemplate = matchCollection.AsEnumerable<Match>().FirstOrDefault().Value;
                matchCollection = endRegex.Matches(contentTemplate);
                string endTemplate = matchCollection.AsEnumerable<Match>().FirstOrDefault().Value;
                contentTemplate = contentTemplate.Replace(beginTemplate, "");
                contentTemplate = contentTemplate.Replace(endTemplate, "");

                string html = string.Empty;
                html += this.MakeResultObject(obj, contentTemplate);
                return html;
            }
            else
            {
                return "";
            }
        }
        #endregion

        #region 解析Object模板对象，并替换样本
        /// <summary>
        /// 解析Object模板对象，并替换样本
        /// </summary>
        /// <param name="objectTemplate">Object模板html</param>
        /// <param name="obj">数据对象</param>
        /// <returns></returns>
        private string ParseObjectTemplateResult(object obj, string objectTemplate)
        {
            Regex beginRegex = new Regex("([{]{2}[\\s]*(BCObject){1}[^}]*\\s*[}]{2})");
            Regex endRegex = new Regex("([{]{2}[/]{1}[\\s]*(BCObject){1}[\\s]*[}]{2})");
            MatchCollection matchCollection = beginRegex.Matches(objectTemplate);
            if (matchCollection.Count > 0)
            {
                string beginTemplate = matchCollection.AsEnumerable<Match>().FirstOrDefault().Value;
                matchCollection = endRegex.Matches(objectTemplate);
                string endTemplate = matchCollection.AsEnumerable<Match>().FirstOrDefault().Value;
                objectTemplate = objectTemplate.Replace(beginTemplate, "");
                objectTemplate = objectTemplate.Replace(endTemplate, "");

                string html = string.Empty;
                html += this.MakeResultObject(obj, objectTemplate);
                return html;
            }
            else
            {
                return "";
            }
        }
        #endregion

        #region 构建结果对象，并替换样本
        /// <summary>
        /// 构建结果对象，并替换样本(主要用于Dto模型字段)
        /// </summary>
        /// <param name="result">方法调用返回值对象</param>
        /// <param name="html">样本Html</param>
        /// <returns></returns>
        private string MakeResultObject(object result, string html)
        {
            if (result == null)
            {
                return "";
            }
            List<string> tagList = this.MatchSampleTag(html);

            foreach (string tag in tagList)
            {
                Dictionary<string, string> dictionary = new Dictionary<string, string>();
                Dictionary<string, string> parseDictionary = new Dictionary<string, string>();
                string sourceTag = tag.Replace("{{", "").Replace("}}", "").Trim().Replace("@@", "").Replace("!!","");
                string simpleTag = sourceTag.IndexOf(".") > -1 ? sourceTag.Substring(0, sourceTag.IndexOf(".")) : sourceTag;
                dictionary.Add(simpleTag, tag);
                if (!simpleTag.Equals(sourceTag))
                {
                    parseDictionary.Add(simpleTag, sourceTag);
                }
                Type type = result.GetType();
                PropertyInfo[] properties = type.GetProperties();
                foreach (PropertyInfo property in properties)
                {

                    if (dictionary.Any(p => p.Key.Equals(property.Name)))
                    {
                        var propertyValue = property.GetValue(result, null);
                        if (propertyValue.IsNotNull())
                        {
                            string value = propertyValue.ToString();
                            if (parseDictionary.Any(p => p.Key.Equals(property.Name)))
                            {
                                string parseValue = parseDictionary[property.Name];
                                string methodName = parseValue.Substring(parseValue.IndexOf("."), parseValue.IndexOf("(") - parseValue.IndexOf(".")).Replace(".", "");
                                string paramsValue = parseValue.Substring(parseValue.IndexOf("("), parseValue.LastIndexOf(")") - parseValue.IndexOf("(")).Replace("(", "").Replace(")", "");
                                while (paramsValue.IndexOf(" ") > -1)
                                {
                                    paramsValue = paramsValue.Replace(" ", "");
                                }
                                value = this.tagParseService.Parse(property.PropertyType, value, methodName, paramsValue);
                            }
                            html = html.Replace(dictionary[property.Name], value);
                        }
                    }
                }
            }

            return html;
        }
        #endregion
        #endregion

        #region 获取结果对象某一字段值
        private object GetResultAnyFieldValue(object result,string fieldName)
        {
            object value = null;
            Type type = result.GetType();
            PropertyInfo[] properties = type.GetProperties();
            foreach (PropertyInfo property in properties)
            {
                if(property.Name == fieldName)
                {
                   value = property.GetValue(result, null);
                }
                //if (dictionary.Any(p => p.Key.Equals(property.Name)))
                //{
                    
                //    //if (parseDictionary.Any(p => p.Key.Equals(property.Name)))
                //    //{
                //    //    string parseValue = parseDictionary[property.Name];
                //    //    string methodName = parseValue.Substring(parseValue.IndexOf("."), parseValue.IndexOf("(") - parseValue.IndexOf(".")).Replace(".", "");
                //    //    string paramsValue = parseValue.Substring(parseValue.IndexOf("("), parseValue.LastIndexOf(")") - parseValue.IndexOf("(")).Replace("(", "").Replace(")", "");
                //    //    while (paramsValue.IndexOf(" ") > -1)
                //    //    {
                //    //        paramsValue = paramsValue.Replace(" ", "");
                //    //    }
                //    //    value = this.tagParseService.Parse(property.PropertyType, value, methodName, paramsValue);
                //    //}
                    
                //}
            }
            return value;
        }
        #endregion

        #region 提取标签
        /// <summary>
        /// 提取For循环模板代码块
        /// </summary>
        /// <param name="html">模板html</param>
        /// <returns></returns>
        private List<string> GetForTemplate(string html)
        {
            string value = html;
            Regex regex = new Regex("[{]{2}\\s*(?<TemplateTag>BCFor)[^}]*\\s*[}]{2}((?<Nested>[{]{2}\\s*\\k<TemplateTag>[^}]*[}]{2})|[{]{2}/\\s*\\k<TemplateTag>\\s*[}]{2}(?<-Nested>)|.*?)*[{]{2}/\\s*\\k<TemplateTag>\\s*[}]{2}", RegexOptions.IgnoreCase | RegexOptions.Multiline | RegexOptions.Singleline);
            List<string> htmls = new List<string>();

            while (regex.IsMatch(value))
            {
                Match match = regex.Match(value);
                htmls.Add(match.Groups[0].Value);
                value = value.Replace(match.Groups[0].Value, "");
            }

            return htmls;
        }
        /// <summary>
        /// 提取Pageable分页模板代码块
        /// </summary>
        /// <param name="html">模板html</param>
        /// <returns></returns>
        private List<string> GetPageableTemplate(string html)
        {
            Regex regex = new Regex("[{]{2}\\s*(?<TemplateTag>BCPagingTag)[^}]*\\s*[}]{2}((?<Nested>[{]{2}\\s*\\k<TemplateTag>[^}]*[}]{2})|[{]{2}/\\s*\\k<TemplateTag>\\s*[}]{2}(?<-Nested>)|.*?)*[{]{2}/\\s*\\k<TemplateTag>\\s*[}]{2}", RegexOptions.IgnoreCase | RegexOptions.Multiline | RegexOptions.Singleline);
            MatchCollection matchCollection = regex.Matches(html);

            List<string> htmls = new List<string>();

            if (matchCollection.Count > 0)
            {
                foreach (Match subMatch in matchCollection)
                {
                    htmls.Add(subMatch.Groups[0].Value);
                }
            }
            return htmls;
        }

        /// <summary>
        /// 提取Content内容模块代码
        /// </summary>
        /// <param name="html"></param>
        /// <returns></returns>
        private List<string> GetContentTemplate(string html)
        {
            Regex regex = new Regex("[{]{2}\\s*(?<TemplateTag>BCContentTag)[^}]*\\s*[}]{2}((?<Nested>[{]{2}\\s*\\k<TemplateTag>[^}]*[}]{2})|[{]{2}/\\s*\\k<TemplateTag>\\s*[}]{2}(?<-Nested>)|.*?)*[{]{2}/\\s*\\k<TemplateTag>\\s*[}]{2}", RegexOptions.IgnoreCase | RegexOptions.Multiline | RegexOptions.Singleline);
            MatchCollection matchCollection = regex.Matches(html);

            List<string> htmls = new List<string>();

            if (matchCollection.Count > 0)
            {

                foreach (Match subMatch in matchCollection)
                {
                    htmls.Add(subMatch.Groups[0].Value);
                }
            }
            return htmls;
        }

        /// <summary>
        /// 提取Object对象模块代码
        /// </summary>
        /// <param name="html"></param>
        /// <returns></returns>
        private List<string> GetObjectTemplate(string html)
        {
            Regex regex = new Regex("[{]{2}\\s*(?<TemplateTag>BCObject)[^}]*\\s*[}]{2}((?<Nested>[{]{2}\\s*\\k<TemplateTag>[^}]*[}]{2})|[{]{2}/\\s*\\k<TemplateTag>\\s*[}]{2}(?<-Nested>)|.*?)*[{]{2}/\\s*\\k<TemplateTag>\\s*[}]{2}", RegexOptions.IgnoreCase | RegexOptions.Multiline | RegexOptions.Singleline);
            MatchCollection matchCollection = regex.Matches(html);

            List<string> htmls = new List<string>();

            if (matchCollection.Count > 0)
            {

                foreach (Match subMatch in matchCollection)
                {
                    htmls.Add(subMatch.Groups[0].Value);
                }
            }
            return htmls;
        }

        /// <summary>
        /// 提取页面Html标签代码块
        /// </summary>
        /// <param name="html">模板html</param>
        /// <param name="tag">html标签</param>
        /// <returns></returns>
        private string GetHtmlTag(string html, string tag)
        {
            Regex regex = new Regex($"(<{tag}>)([\\S\\s]*)(<\\/{tag}>)", RegexOptions.IgnoreCase | RegexOptions.Multiline | RegexOptions.Singleline);
            MatchCollection matchCollection = regex.Matches(html);

            string htmlHead = string.Empty;

            if (matchCollection.Count > 1)
            {
                throw new ArgumentException("一个页面仅应只有一个head标签区域!");
            }
            else if (matchCollection.Count == 1)
            {
                htmlHead = matchCollection[0].Groups[0].Value;
            }
            return htmlHead;
        }
        private List<string> GetHtmlTags(string html, string tag)
        {
            Regex regex = new Regex($"((<{tag})([^<]+)(</{tag}>))|((<{tag})([^>]+)([>]))", RegexOptions.IgnoreCase | RegexOptions.Multiline | RegexOptions.Singleline);
            MatchCollection matchCollection = regex.Matches(html);

            List<string> htmls = new List<string>();

            if (matchCollection.Count > 0)
            {
                foreach (Match subMatch in matchCollection)
                {
                    htmls.Add(subMatch.Groups[0].Value);
                }
            }
            return htmls;
        }
        /// <summary>
        /// 提取系统配置标签(主要用于站点配置表字段)
        /// </summary>
        /// <param name="html">模板html</param>
        /// <returns></returns>
        private List<string> MatchSystemDefinedTag(string html)
        {
            Regex regex = new Regex("[{]{2}[\\s]*[##]{2}[a-zA-Z_]*.?[^}]*[\\s]*[}]{2}");
            MatchCollection matchCollection = regex.Matches(html);
            return matchCollection.AsEnumerable<Match>().Select(p => p.Value).ToList();
        }
        /// <summary>
        /// 提取系统配置标签(主要用于站点配置表字段)
        /// </summary>
        /// <param name="html">模板html</param>
        /// <returns></returns>
        private List<string> MatchSystemConfigurationTag(string html)
        {
            Regex regex = new Regex("[{]{2}[\\s]*[$]{2}[a-zA-Z_]*.?[^}]*[\\s]*[}]{2}");
            MatchCollection matchCollection = regex.Matches(html);
            return matchCollection.AsEnumerable<Match>().Select(p => p.Value).ToList();
        }

        /// <summary>
        /// 提取动态标签(主要用于模板标记)
        /// </summary>
        /// <param name="html">模板html</param>
        /// <returns></returns>
        private List<string> MatchDynamicTag(string html)
        {
            List<string> list = new List<string>();
            Regex regex = new Regex("[{]{2}[\\s]*[!]{2}[a-zA-Z_]*.?[^}]*[\\s]*[}]{2}");
            MatchCollection matchCollection = regex.Matches(html);
            list.AddRange(matchCollection.AsEnumerable<Match>().Select(p => p.Value).ToList());
            if (!list.Any())
            {
                Regex regexDynamic = new Regex("[{]{2}[\\s]*[!]{2}[a-zA-Z_]*.?[^}]*[\\s]*[}]{2}");
                matchCollection = regexDynamic.Matches(html);
                list.AddRange(matchCollection.AsEnumerable<Match>().Select(p => p.Value).ToList());
            }
            return list;
        }
        /// <summary>
        /// 提取样本标签(主要用于Dto模型字段)
        /// </summary>
        /// <param name="html">模板html</param>
        /// <returns></returns>
        private List<string> MatchSampleTag(string html)
        {
            Regex regex = new Regex("[{]{2}[\\s]*(([@]{2}([a-zA-Z_]*[.]{1}[^}]*))|(([@]{2}[a-zA-Z_]*)[\\s]*))[}]{2}");
            MatchCollection matchCollection = regex.Matches(html);
            return matchCollection.AsEnumerable<Match>().Select(p => p.Value).ToList();
        }
        #endregion
        #endregion

    }
}
